﻿using System.ComponentModel;
using System.ComponentModel.Design;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PrismFactory.SoftwareFactory.Views.CreateSolution;
using PrismGuidancePackage.Views.Services;
using Rhino.Mocks;

namespace PrismGuidancePackage.Views.Tests
{
    [TestClass]
    public class EnsureEntlibAssembliesPathPageViewModelFixture
    {
        private EnsureEntlibAssembliesPathPageViewModel viewModel;
        private IDictionaryService stubDictionaryService;
        private IFileSystemService stubFileSystemService;

        [TestInitialize]
        public void Setup()
        {
            stubDictionaryService = MockRepository.GenerateStub<IDictionaryService>();
            stubFileSystemService = MockRepository.GenerateStub<IFileSystemService>();
            viewModel = new EnsureEntlibAssembliesPathPageViewModel(stubDictionaryService, stubFileSystemService);
        }

        [TestMethod]
        public void ValidWhenEntlibAssembliesPathExist()
        {
            const string path = "myPath";

            stubDictionaryService.Stub(s => s.GetValue(EnsureEntlibAssembliesPathPageViewModel.EntlibAssembliesPathKey)).Return(path);
            stubFileSystemService.Stub(s => s.PathExists(path)).Return(true);
            Assert.IsNull((viewModel as IDataErrorInfo)[EnsureEntlibAssembliesPathPageViewModel.EntlibAssembliesPathKey]);
        }

        [TestMethod]
        public void InvalidWhenEntlibAssembliesPathDoesNotExist()
        {
            const string path = "myPath";

            stubDictionaryService.Stub(s => s.GetValue(EnsureEntlibAssembliesPathPageViewModel.EntlibAssembliesPathKey)).Return(path);
            stubFileSystemService.Stub(s => s.PathExists(path)).Return(false);
            Assert.IsNotNull((viewModel as IDataErrorInfo)[EnsureEntlibAssembliesPathPageViewModel.EntlibAssembliesPathKey]);
        }
    }
}